package com.tomvian.screens 
{	
	/**
	 * AbstractTransition
	 * @author Thomas Vian
	 */
	public class AbstractTransition
	{
		//--------------------------------------------------------------------------
		//
		//  Properties
		//
		//--------------------------------------------------------------------------
		
		public var screenManager:ScreenManager;
		
		protected var _fromScreen:AbstractScreen;
		protected var _toScreen:AbstractScreen;
		
		protected var _overlap:Boolean = false;
		protected var _inFront:Boolean = true;
		
		//--------------------------------------------------------------------------
		//
		//  Getters / Setters
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		
		public function AbstractTransition()
		{
			
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		public function play(fromScreen:AbstractScreen, toScreen:AbstractScreen):void
		{
			_fromScreen = fromScreen;
			_toScreen = toScreen;
			
			_fromScreen.exitStart(_toScreen);
		}
		
		protected function swap():void
		{
			swapTo(_toScreen, true, _overlap, _inFront);
		}
		
		protected function onTransitionComplete():void
		{
			if (_overlap)
			{
				if (_fromScreen.graphic.parent) _fromScreen.graphic.parent.removeChild(_fromScreen.graphic);
				
				_fromScreen.exitFinish(_toScreen);
			}
			
			_toScreen.enterFinish(_fromScreen);
			
			finishTransition();
		}
		
		protected function swapTo(screen:AbstractScreen, inTransition:Boolean = false, overlap:Boolean = false, inFront:Boolean = true):void
		{
			screenManager.swapTo(screen, inTransition, overlap, inFront);
		}
		
		protected function finishTransition():void
		{
			screenManager.finishTransition();
		}
	}
}